package com.qyy.springblog.service;


import com.qyy.springblog.mapper.BlogMapper;
import com.qyy.springblog.model.BlogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;
    public List<BlogInfo> queryBlogList() {

        List<BlogInfo> blogInfos = blogMapper.selectAllBlog();
        for (BlogInfo blog: blogInfos){
            String result = blog.getContent();
            result = result.replace("#","");
            if(result.length() >= 66){
                result = result.substring(0,65)+"......";
            }
            blog.setContent(result);
        }
        return blogInfos;
    }

    public BlogInfo queryBlogById(Integer blogId) {
        return blogMapper.selectById(blogId);
    }

    public Integer countsBlog(){return blogMapper.countsBlog();}

    public Integer publishBlog(BlogInfo blogInfo) {
        return blogMapper.interBlog(blogInfo);
    }

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogMapper.updateById(blogInfo);
    }
}
